{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This notebook illustrates how to obtain an explaination of the different corrections being applied in the Materials Project."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import re\n",
    "from pymatgen.entries.computed_entries import ComputedEntry\n",
    "from pymatgen.entries.compatibility import MaterialsProjectCompatibility"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "from pymatgen import MPRester\n",
    "\n",
    "#To do our testing, let's use the MPRester to get a sample computed entry from the Materials Project.\n",
    "m = MPRester()\n",
    "entries = m.get_entries(\"LiFePO4\")\n",
    "entry = entries[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "compat = MaterialsProjectCompatibility()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The uncorrected value of the energy of P4 Fe4 O16 Li4 is -191.338121 eV\n",
      "The following corrections / screening are applied for MaterialsProjectCompatibility:\n",
      "\n",
      "MP Potcar Correction correction: Checks that POTCARs are valid within a pre-defined input set. This\n",
      "    ensures that calculations performed using different InputSets are not\n",
      "    compared against each other.\n",
      "\n",
      "    Entry.parameters must contain a \"potcar_symbols\" key that is a list of\n",
      "    all POTCARs used in the run. Again, using the example of an Fe2O3 run\n",
      "    using Materials Project parameters, this would look like\n",
      "    entry.parameters[\"potcar_symbols\"] = ['PAW_PBE Fe_pv 06Sep2000',\n",
      "    'PAW_PBE O 08Apr2002'].\n",
      "\n",
      "This correction does not make any changes to the energy.\n",
      "------------------------------\n",
      "MP Gas Correction correction: Correct gas energies to obtain the right formation energies. Note that\n",
      "    this depends on calculations being run within the same input set.\n",
      "\n",
      "For the entry, this correction has the value -11.236640 eV.\n",
      "------------------------------\n",
      "MP Advanced Correction correction: This class implements the GGA/GGA+U mixing scheme, which allows mixing of\n",
      "    entries. Entry.parameters must contain a \"hubbards\" key which is a dict\n",
      "    of all non-zero Hubbard U values used in the calculation. For example,\n",
      "    if you ran a Fe2O3 calculation with Materials Project parameters,\n",
      "    this would look like entry.parameters[\"hubbards\"] = {\"Fe\": 5.3}\n",
      "    If the \"hubbards\" key is missing, a GGA run is assumed.\n",
      "\n",
      "    It should be noted that ComputedEntries assimilated using the\n",
      "    pymatgen.apps.borg package and obtained via the MaterialsProject REST\n",
      "    interface using the pymatgen.matproj.rest package will automatically have\n",
      "    these fields populated.\n",
      "\n",
      "For the entry, this correction has the value -10.932000 eV.\n",
      "------------------------------\n",
      "The final energy after corrections is -213.506761\n"
     ]
    }
   ],
   "source": [
    "compat.explain(entry)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
